package com.bto.solar.work.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;

import java.sql.Timestamp;

/**
 * @author 王小波
 * @description:
 * @date 2023/7/14 15:12
 */
@Slf4j
@Configuration
public class MybatisMetaObjectHandler implements MetaObjectHandler {
    //插入时的填充策略
    @Override
    public void insertFill(MetaObject metaObject) {
//        log.info("start insert fill ....");
        //三个参数：字段名，字段值，元对象参数
        this.setFieldValByName("createTime", new Timestamp(System.currentTimeMillis()) , metaObject);
        this.setFieldValByName("updateTime",new Timestamp(System.currentTimeMillis()) , metaObject);

    }
    //修改时的填充策略
    @Override
    public void updateFill(MetaObject metaObject) {
//        log.info("start update fill ....");
        this.setFieldValByName("updateTime",new Timestamp(System.currentTimeMillis()),metaObject);
    }
}
